import { request } from 'umi';

// 获取设备分组列表
export async function getDeviceGroupList(params) {
  return request('/api/v1/device/group', {
    method: 'GET',
    params,
  });
}

// 获取设备分组详情
export async function getDeviceGroupDetail(id) {
  return request(`/api/v1/device/group/${id}`, {
    method: 'GET',
  });
}

// 创建设备分组
export async function createDeviceGroup(data) {
  return request('/api/v1/device/group', {
    method: 'POST',
    data,
  });
}

// 更新设备分组
export async function updateDeviceGroup(data) {
  return request(`/api/v1/device/group/${data.id}`, {
    method: 'PUT',
    data,
  });
}

// 删除设备分组
export async function deleteDeviceGroup(id) {
  return request(`/api/v1/device/group/${id}`, {
    method: 'DELETE',
  });
}

// 添加设备到分组
export async function addDevicesToGroup(groupId, deviceIds) {
  return request('/api/v1/device/group/add_devices', {
    method: 'POST',
    data: {
      group_id: groupId,
      device_ids: deviceIds,
    },
  });
}

// 从分组中移除设备
export async function removeDevicesFromGroup(groupId, deviceIds) {
  return request('/api/v1/device/group/remove_devices', {
    method: 'POST',
    data: {
      group_id: groupId,
      device_ids: deviceIds,
    },
  });
}

// 获取分组下的设备列表
export async function getDevicesByGroup(params) {
  return request('/api/v1/device/group/devices', {
    method: 'GET',
    params,
  });
}

// 获取设备所属的分组列表
export async function getGroupsByDevice(deviceId) {
  return request('/api/v1/device/groups', {
    method: 'GET',
    params: {
      device_id: deviceId,
    },
  });
}